<?php

/**
 * Created by PhpStorm.
 * User: TC
 * Date: 2016/1/16
 * Time: 10:00
 * 小工具
 */
class Util
{
  /*
   * 转换获取post、Put方法的传入参数
   * @return : Type Array
   */
  public static function TranInputData()
  {
    return json_decode(file_get_contents("php://input"), true);
  }

  /*
   * 检查管理员登陆状态
   */
  public static function CheckAuthority($login_field, $user_field, $role_field, $roleArr)
  {
    if(!isset($_SESSION[$login_field])){
      ResponseMsg::ResponseErrorMsgArr([401,'请先登录']);
      return;
    }
    if ((!$_SESSION[$login_field]) || (!$_SESSION[$user_field]) || (empty($_SESSION[$user_field]))) {
      ResponseMsg::ResponseErrorMsgArr([401, '未登录']);
      return;
    }
    if (!in_array($_SESSION[$user_field][$role_field],$roleArr)) {
      ResponseMsg::ResponseErrorMsgArr([403,'没有权限']);
      return;
    }
  }
}